#include <iostream>
using namespace std;

const int N = 1e5 + 10;

int e[N],pre[N],ne[N],id,h,mp[N];

int main(){
	int n;
	cin >> n;
	id++;
	int j = 1;
	e[id] = j;
	mp[j] = id;
	while(--n){
		int k,p;
		cin >> k >> p;
		int pok = mp[k];
		id++;
		j++;
		e[id] = j;
		mp[j] = id;
		if(p == 1){
			ne[id] = ne[pok];
			pre[id] = pok;
			pre[ne[pok]] = id;
			ne[pok] = id;
			
		}
		else if(p == 0){
			ne[id] = pok;
			pre[id] = pre[pok];
			ne[pre[pok]] = id;
			pre[pok] = id;
		}
	}
	int m;
	cin >> m;
	while(m--){
		int x;
		cin >> x;
		int pox = mp[x];
		pre[ne[pox]] = pre[pox];
		ne[pre[pox]] = ne[pox];
		mp[x] = -1;
	}
	for(int i = ne[h];i;i = ne[i]){
		cout << e[i] << " ";
	}
	return 0;
} 
